# -*- coding: utf-8 -*-

# __date:       2021/6/24
# __author:     Yang Chao
# __function:   Longest Substring Without Repeating Characters


class Solution:

    def lengthOfLongestSubstring(self, s: str) -> int:
        ans, l, r = 0, 0, 0
        t_set = set()
        while r < len(s):
            if s[r] not in t_set:
                t_set.add(s[r])
                r += 1
                ans = max(ans, r - l)
            else:
                t_set.remove(s[l])
                l += 1
        return max(ans, r - l)
